from collections.abc import Iterable, Iterator

# print(isinstance("hello",Iterable),isinstance([],Iterable))
#
# print(isinstance("hello",Iterator),isinstance([],Iterator))

t0 = (i for i in range(10) if i % 2)
print(type(t0), isinstance(t0, Iterable), isinstance(t0, Iterator))
#
# while True:
#     try:
#         e = next(t0)
#         print(e)
#     except StopIteration as e:
#         print(f"异常： 遍历完成")
#         break

# from collections.abc import Iterable,Iterator
#
# class Mystr:
#     def __init__(self,s):
#         self.s = s
#         self.index = 0
#
#     def __iter__(self):
#         return self
#
#     def __next__(self):
#         if self.index >= len(self.s):
#             raise StopIteration
#         else:
#             e = self.s[self.index]
#             self.index += 1
#             return e
#
#
# my = Mystr('睡不醒喽')
# print(type(my),isinstance(my,Iterator),isinstance(my,Iterable))
#
# while True:
#     try:
#         e = next(my)
#         print(e)
#     except StopIteration:
#         break
